package com.ep.baselibrary.base;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/3.
 */

public abstract class BaseActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initBeforeView();
        setContentView(getContentViewId());
        ButterKnife.bind(this);
        initTitle();
        initView();
        initData();
    }

    /**
     *加载布局之前要做的初始化
     */
    protected void initBeforeView() {

    }

    /**
     * 初始化头部
     */
    protected abstract void initTitle();

    /**
     * 初始化界面
     */
    protected abstract void initView();

    /**
     * 初始化数据
     */
    protected abstract void initData();

    /**
     * 返回当前activity所显示布局id
     * @return
     */
    protected abstract int getContentViewId();

    /**
     *查找页面布局ID所对应控件对像,不用强制转换
     * @param resId
     * @param <T>
     * @return
     */
    protected <T>T findViewByIds(int resId){
        return (T)findViewById(resId);
    }

    /**
     * 跳转activity
     * @param cls
     */
    protected void startActivity(Class<?> cls){
        startActivity(new Intent(this,cls));
    }
}
